//
//  JTMeSquareButton.m
//  百思不得姐
//
//  Created by Robin Zhang on 2016/12/27.
//  Copyright © 2016年 BeiJingWangDianJieTong. All rights reserved.
//

#import "JTMeSquareButton.h"
#import "JTMeSquare.h"
#import <UIButton+WebCache.h>

@implementation JTMeSquareButton

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setBackgroundImage:[UIImage imageNamed:@"mainCellBackground"] forState:UIControlStateNormal];
        
        [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
        [self.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.imageView setJt_y:self.jt_height * 0.15];
    [self.imageView setJt_height:self.jt_height * 0.5];
    [self.imageView setJt_width:self.imageView.jt_height];
    [self.imageView setJt_centerX:self.jt_width * 0.5];
    
    [self.titleLabel setJt_x:0];
    [self.titleLabel setJt_y:self.imageView.jt_bottom];
    [self.titleLabel setJt_width:self.jt_width];
    [self.titleLabel setJt_height:self.jt_height - self.titleLabel.jt_y];
}

- (void)setSquare:(JTMeSquare *)square {
    
    _square = square;
    
    [self setTitle:square.name forState:UIControlStateNormal];
    [self sd_setImageWithURL:[NSURL URLWithString:square.icon] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"setup-head-default"]];
}

@end
